package com.bw.dao;

import com.bw.pojo.Student;
import com.bw.util.JDBC;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/***************************
 FileAction:

 CreateTime:2022-05-09 11:00
 Author:Aaking-aline
 ****************************/
public class StudentDao {

    public List<Student> selectAllStudent() throws SQLException {
        String sql = "select * from student";

        Connection conn = JDBC.getConnection();

        PreparedStatement ps = conn.prepareStatement(sql);

        ResultSet rs = ps.executeQuery();

        List<Student> list = new ArrayList<>();

        while(rs.next()){
            Student stu = new Student(rs.getInt(1),
                    rs.getString(2),
                    rs.getInt(3),
                    rs.getDate(4));
            list.add(stu);
        }
        return list;
    }


}
